package LeetCode.month02.day40;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class No383 {
    public boolean canConstruct(String ransomNote, String magazine) {
        Map<Character,Integer> source = new TreeMap<>();
        for (int i = 0; i < ransomNote.length(); i++) {
            char c = ransomNote.charAt(i);
            source.put(c,source.getOrDefault(c,0)+1);
        }
        Map<Character,Integer> dest = new HashMap<>();
        for (int i = 0; i < magazine.length(); i++) {
            char c = magazine.charAt(i);
            dest.put(c,dest.getOrDefault(c,0)+1);
        }
        for (Character c : source.keySet()) {
            if(dest.get(c)==null||source.get(c)>dest.get(c)){
                return false;
            }
        }
        return true;
    }
}
